/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.model.bo.excel.asset;

import cn.ac.nercis.pes.model.dto.evaluation.asset.KeyDataDTO;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

/**
 * 重要数据资产信息类（导出/导入）
 * @author zpy
 * @version 1.0.0
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class KeyDataBO extends BaseExcelBO {

    @ExcelProperty(value = "*数据",order = 1)
    private String data;
    @ExcelProperty(value = "*描述",order = 2)
    private String describe;
    @ExcelProperty(value = "*所属应用",order = 3)
    private String ownedApp;
    @ExcelProperty(value = "存储位置",order = 4)
    private String location;
    @ExcelProperty(value = "*安全需求", order = 5)
    private String require;
    @ExcelProperty(value = "备注",order = 6)
    private String desc;

    @ExcelIgnore
    private KeyDataDTO source;

    public boolean isEmpty(){
        return StringUtils.isAllBlank(data,describe,ownedApp,location,require,desc);
    }

    public boolean validRequired(){
        return !StringUtils.isAnyBlank(data,describe,ownedApp,require);
    }

    public boolean equalsDTO(@NonNull KeyDataDTO dto){
        boolean isUse = true;
        return StringUtils.equals(data,dto.getData())
                && StringUtils.equals(ownedApp,dto.getOwnedApp())
                && StringUtils.equals(describe,dto.getDescribe())
                && StringUtils.equals(location,dto.getLocation())
                && StringUtils.equals(require,dto.getRequire())
                && (isUse == dto.getIsUse())
                && StringUtils.equals(desc,dto.getDesc());
    }
}